package cn.dujc.superkid.bean;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.Arrays;
import java.util.List;

import cn.dujc.core.adapter.entity.IExpandable;

/**
 * 数据实体实现IExpandable，范型即展开后内部的类型
 * @author du
 * date 2018/9/7 下午3:46
 */
public class Main2Entity implements IExpandable<Main2Entity.InnerEntity> {

    //这个即展开后的数据，即二级列表，同样需要实现IExpandable
    public static class InnerEntity implements IExpandable<String>{

        public InnerEntity(ExamineListResult.ExListEntity child) {
            this.child = child;
        }

        private final ExamineListResult.ExListEntity child;

        public ExamineListResult.ExListEntity getChild() {
            return child;
        }


        public static class ExListEntity implements Parcelable {
            /**
             * id : 161
             * ex_title : 11月份月考（2017年）
             * addtime : 1512004030
             * latest : 2
             */

            private String id;//知识点id
            private String ex_title;//试卷标题
            private String addtime;//试卷添加时间戳
            private String latest;//是否是最新（1-不是，2-是最新）

            public String getId() { return id;}

            public void setId(String id) { this.id = id;}

            public String getEx_title() { return ex_title;}

            public void setEx_title(String ex_title) { this.ex_title = ex_title;}

            public String getAddtime() { return addtime;}

            public void setAddtime(String addtime) { this.addtime = addtime;}

            public String getLatest() { return latest;}

            public void setLatest(String latest) { this.latest = latest;}

            @Override
            public int describeContents() { return 0; }

            @Override
            public void writeToParcel(Parcel dest, int flags) {
                dest.writeString(this.id);
                dest.writeString(this.ex_title);
                dest.writeString(this.addtime);
                dest.writeString(this.latest);
            }

            public ExListEntity() {}

            protected ExListEntity(Parcel in) {
                this.id = in.readString();
                this.ex_title = in.readString();
                this.addtime = in.readString();
                this.latest = in.readString();
            }

            public static final Creator<ExamineListResult.ExListEntity> CREATOR = new Creator<ExamineListResult.ExListEntity>() {
                @Override
                public ExamineListResult.ExListEntity createFromParcel(Parcel source) {return new ExamineListResult.ExListEntity(source);}

                @Override
                public ExamineListResult.ExListEntity[] newArray(int size) {return new ExamineListResult.ExListEntity[size];}
            };
        }

        @Override
        public boolean isExpanded() {//没有下一级，这个返回false
            return false;
        }

        @Override
        public void setExpanded(boolean expanded) { }

        @Override
        public List<String> getSubItems() {
            return null;
        }

        @Override
        public int getLevel() {
            return 1;//level要与顶级不同
        }
    }

    public Main2Entity(String title, InnerEntity... child) {
        this.title = title;
        this.child = Arrays.asList(child);
    }

    private boolean mExpanded;//因为这个是顶级，有展开与否的状态，所以需要存放状态

    private String title;
    private List<InnerEntity> child;

    public String getTitle() {
        return title;
    }

    public List<InnerEntity> getChild() {
        return child;
    }

    @Override
    public boolean isExpanded() {
        return mExpanded;
    }

    @Override
    public void setExpanded(boolean expanded) {
        mExpanded = expanded;
    }

    @Override
    public List<InnerEntity> getSubItems() {
        return child;
    }

    @Override
    public int getLevel() {
        return 0;
    }
}
